<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@page import="com.yaodian100.mall.member.util.UserData"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib uri="/WEB-INF/tld/importTag.tld" prefix="importTag"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<c-rt:set var="frontHtmlPath" value='<%=ServerValue.getFrontApachePath()%>'/>
<c-rt:set var="hostName" value='<%=request.getServerName()%>'/>
<c-rt:set var="frontContextPath" value='<%=ServerValue.getFrontContextPath() %>'/>
<link rel="stylesheet" href="/css/jquery-ui-1.7.2.custom.css" type="text/css" media="screen" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery-ui-1.7.2.custom.min.js"></script>
<%
	UserData userData = new UserData(request,response);
%>
<script language="javascript" >
$().ready( function() {
	$("#cartItems").text("<%=StringUtils.defaultString(userData.readRawValue(UserData.NAME_YAODIAN100_CART_ITEMS),"0")%>");
});
</script>

<script language="javascript" >
var url;
$().ready( function() {
	$("#waitactivate_nonmember_dialog").dialog({
		autoOpen: false,
		bgiframe: true,
		width:505,
		modal: true
	});

	$("#to_activate_nonmember_dialog").dialog({
		autoOpen: false,
		bgiframe: true,
		width:505,
		modal: true
	});

	$("#topbar_to_resend_submit").click(function(){
		$("#topbar_waitactivateForm").submit();
		return false;
	});
	
	$("#topbar_to_activate_close").click(function(){
		$("#waitactivate_nonmember_dialog").dialog('close');
	});

	$("#topbar_to_activate_submit").click(function(){
		$("#topbar_loginIDTip").html('');
		var isCorrect = true;
		$("#topbar_set_loginID").val(jQuery.trim($("#topbar_set_loginID").val()).toLowerCase());
		var text = $("#topbar_set_loginID").val();
		var idlength=text.length+chineseCount(text);  
		if(idlength==0){
			$("#topbar_loginIDTip").html('<span class="msg rn">请输入帐户名</span>');
			isCorrect = false;
		}else if(idlength<4||idlength>20){
			$("#topbar_loginIDTip").html('<span class="msg rn">帐户名长度不符规定</span>');
			isCorrect = false;
		}else if(isAllNum(text)){
			$("#topbar_loginIDTip").html('<span class="msg rn">帐户名不能全为数字</span>');
			isCorrect = false;
		}else if(text.indexOf(' ')>=0){
			$("#topbar_loginIDTip").html('<span class="msg rn">帐户名不能含有空白</span>');
			isCorrect = false;
		}else if(text.match(/^[\u0391-\uFFE5\w]+$/)==null){
			$("#topbar_loginIDTip").html('<span class="msg rn">只能使用小写英文字母、中文、数字</span>');
			isCorrect = false;
		}
		if(isCorrect){
			$.post("<%=ServerValue.getFrontContextPath()%>/nonMember/goactivate.do",{mail:$("#to_activate_showMail").text(),loginID:$("#topbar_set_loginID").val()},topbarActivateResult,"json");
		}
	});
});

function nonmemberLoginCheckResult(result){
	if(result=='login'||result=='notLogin'){
		window.location.href = url; 
	}else{
		showNonmemberDialog(result);
	}
}

function showNonmemberDialog(result){
	 if(result.split('#')[0]=='waitActivate'){
		$("#nonmember_mail").val(result.split('#')[1]);
		$("#nonmember_loginID").val(result.split('#')[2]);
		$("#waitActivate_showMail").html(result.split('#')[1]);
		$("#waitactivate_nonmember_dialog").dialog('open');
	}else if(result.split('#')[0]=='needToActivate'){
		$("#nonmember_mail").val(result.split('#')[1]);
		$("#to_activate_showMail").html(result.split('#')[1]);
		$("#to_activate_nonmember_dialog").dialog('open');
	}
}
function chineseCount(word){
    var length=0;
    for(var cc=0;cc<word.length;cc++){
       var c = word.charCodeAt(cc);
      if (!(c>=32&&c<=126)) length++;
    }
    return length;
}

function isAllNum(str){
	for(var i=0;i<str.length;i++){
		var c = str.charCodeAt(i);
		if(c > 57 || c < 48)
			return false;
	}
	return true;
}
function topbarActivateResult(result){					
	if(result == 'ok' ){
		$("#nonmember_loginID").val($("#topbar_set_loginID").val());
		$("#nonmember_mail").val($("#to_activate_showMail").text());
		$("#topbar_waitactivateForm").submit();
		return false;
	}else if(result == 'id_exist'){
		$("#topbar_loginIDTip").html('<span class="msg rn">该帐户名已被使用</span>');
	}
}

function checkLoginMember(gotoUrl){
	url = gotoUrl;
	$.post("<%=ServerValue.getFrontContextPath()%>/nonMember/checkLogin.do",{},nonmemberLoginCheckResult,"json");
}
function bookmarksite(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "");
} 
</script>
<div id="waitactivate_nonmember_dialog" title="会员功能仅限会员使用" class="nomember-order-end" style="display:none;">
    <p class="txt-m"><strong>很抱歉，会员功能仅限耀点100会员使用!</strong></p>
    <p class="notyet">我们已向<strong class="txt-rd" id="waitActivate_showMail"></strong>发送验证邮件<br />
     	请您立即登录该邮箱，并点击邮件中的链接地址，即可完成注册。</p>
	<div class="join-area">
    <p align="center"><a href="javascript:;" class="btn-mid-13" id="topbar_to_resend_submit">重发验证邮件或更改其他邮箱</a> <a href="javascript:;" class="btn-mid" id="topbar_to_activate_close">稍后再看看</a></p>
    </div>
</div>
<div id="to_activate_nonmember_dialog" title="会员功能仅限会员使用" class="nomember-order-end" style="display:none;">
    <p class="txt-m"><strong>很抱歉，会员功能仅限耀点100会员使用!</strong></p>
    <p class="nomb-msg">接著设定帐户名并激活邮箱，就可以成为会员，<br>享受更多会员专属服务与不定期积分与礼券发放优惠！</p>
    <div class="join-area">
       	<p><strong>联络邮箱：</strong><span class="txt-rd" id="to_activate_showMail"></span></p>
        <p><div class="f-lt"><strong>设定帐户名：</strong></div><div class="f-lt"><input size="20" maxlength="20" id="topbar_set_loginID" name="loginID"/>  <span style="display:block" class="txt-gy">请用小写英文字母、中文、数字,长度2-10个汉字或4-20个字符。</span><span style="display:block" id="topbar_loginIDTip"></span></div></p>
        <p align="center"><a href="javascript:;" id="topbar_to_activate_submit"><img src="/images/shoppingcar/joinbtn.gif" border="0" class="btn"></a></p>
	</div>
</div>
<form action="<%=ServerValue.getFrontContextPath()%>/waitactivate.do" method="post" id="topbar_waitactivateForm" name="topbar_waitactivateForm">
<input type="hidden" id="nonmember_loginID" name="loginID" />
<input type="hidden" id="nonmember_mail" name="mail"/>
</form>
<ul class="top-bar">
     <li class="tp-more" onmouseover="$('#tpyd-list').show();" onmouseout="$('#tpyd-list').hide();"><a href="http://${hostName}${frontContextPath}/member/myyaodian.do?hpp=Itpbar_1">我的耀点100</a>
     	<div id="tpyd-list" style="display:none;">
       		<p><a href="http://${hostName}${frontContextPath}/member/myOrder/showOrders.do?t=T&p=1&hpp=Itpbar_1">我的订单</a></p>
            <p><a href="javascript:;" onclick="javascript:checkLoginMember('http://${hostName}${frontContextPath}/member/myCollection/toproductc.do?hpp=Itpbar_1');">我的收藏盒</a></p>
            <p><a href="javascript:;" onclick="javascript:checkLoginMember('http://${hostName}${frontContextPath}/member/myBonus/tomybonus.do?hpp=Itpbar_1');">我的积分</a></p>
            <p><a href="javascript:;" onclick="javascript:checkLoginMember('http://${hostName}${frontContextPath}/member/myCoupon/tomycoupon.do?hpp=Itpbar_1');">我的礼券</a></p>
            <p><a href="http://${hostName}${frontContextPath}/member/myGiftcard/tomygiftcard.do?hpp=Itpbar_1">我的礼品卡</a></p>
         </div>
     </li>
     <li><a href="/help/?hpp=Itpbar_2">帮助中心</a></li>
     <li><a href="http://${hostName}${frontContextPath}/shopping/cart.do?hpp=Itpbar_4" class="icon-car">购物车(<strong id="cartItems" class="txt-rd">0</strong>)</a></li>
     <li class="tp-more" onmouseover="$('#tpnavi-list').show();" onmouseout="$('#tpnavi-list').hide();">网站导航
     <importTag:static path="${frontHtmlPath}/pages/header/itop_navi.html"/>
     </li>
     <li><a href="javascript:;" onClick="javascript:traceVirtualPage('/index.do?hpp=Itpbar_7'); bookmarksite('耀点100 - 中国流行女性百货商城！', 'http://${hostName}');">收藏本站</a></li>
     <li class="service-num">客服热线：<img src="/images/4001168100.gif" alt="4001-168-100"></li>
     <li class="web-chat"><a href="/help/11_webchat.html?hpp=IItpbar_5"><img src="/images/icon_webchat.gif" alt="在线客服" /></a>
    </li>
</ul>